package com.franklin.java.api.psi.data;

import com.intellij.psi.PsiElement;
import com.intellij.psi.PsiMethodCallExpression;
import com.intellij.psi.PsiType;

import java.util.Objects;

/**
 * @author Franklin
 * @since 2021/8/6 17:29
 */
public class PsiData {

    private String type;
    private String value;
    private PsiElement psiElement;
    private String typeFullName;
    private PsiElement originElement;

    public PsiData(String type, String value, PsiElement psiElement, String typeFullName, PsiElement originElement) {
        this.type = type.trim();
        this.value = value.trim();
        this.psiElement = psiElement;
        this.typeFullName = typeFullName.trim();
        this.originElement = originElement;
        if (psiElement instanceof PsiMethodCallExpression){
            PsiMethodCallExpression psiMethodCallExpression = (PsiMethodCallExpression) psiElement;
            PsiType psiType = psiMethodCallExpression.getType();
            if (Objects.nonNull(psiType)) {
                this.type = psiType.getPresentableText();
            }
        }
    }

    public PsiElement getOriginElement() {
        return originElement;
    }

    public String getTypeFullName() {
        return typeFullName;
    }

    public String getType() {
        return type;
    }

    public String getValue() {
        return value;
    }

    public PsiElement getPsiElement() {
        return psiElement;
    }

    @Override
    public String toString() {
        return type + ":" + value;
    }
}
